﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Entity;
using Micronet.OpenWeb.Utils;
using Telerik.Web.UI;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.Blog
{
    public partial class UserInBlogFriendGroupAdmin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void IsDeletedCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isDeletedCheckBox = (OwCheckBox)sender;
            var obj = OwUsersInBlogFriendGroupsBLL.OwGetEntity(isDeletedCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsDeleted = isDeletedCheckBox.Checked.ToString().OwToBoolean();
            if (OwUsersInBlogFriendGroupsBLL.OwSave(obj) > 0)
            {
                UsersInBlogFriendGroupsdv.Rebind();
                Alert();
            }
        }

        protected void IsAprrovedCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isAprrovedCheckBox = (OwCheckBox)sender;
            var obj = OwUsersInBlogFriendGroupsBLL.OwGetEntity(isAprrovedCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsApproved = isAprrovedCheckBox.Checked.ToString().OwToBoolean();
            if (OwUsersInBlogFriendGroupsBLL.OwSave(obj) > 0)
            {
                UsersInBlogFriendGroupsdv.Rebind();
                Alert();
            }
        }
        protected void Alert()
        {
            //MessageNotification.Text = Resources.OpenWeb.ItemUpdateSuccessfullyLabel;
            //MessageNotification.Title = Resources.OpenWeb.ItemUpdateSuccessfullyLabel;
            //MessageNotification.Show();
        }

        protected void UsersInBlogFriendGroupsdv_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                var editform = (GridEditFormItem)e.Item;
                var UserNameCbb = editform.FindControl("UserNameCbb") as OwComboBox;
                UserNameCbb.DataSource = Membership.GetAllUsers();
                MembershipUserCollection users = Membership.GetAllUsers();
                foreach (MembershipUser user in users)
                {                    
                    UserNameCbb.Items.Add(new RadComboBoxItem(user.UserName,user.ProviderUserKey.ToString()));
                }
                UserNameCbb.DataBind();
            }
        }

        protected void IsDeletedCheckBox_CheckedChanged1(object sender, EventArgs e)
        {

        }

        protected void IsAprrovedCheckBox_CheckedChanged1(object sender, EventArgs e)
        {

        }

    }
}